//
//  L_PlayListView.m
//  音悦咖
//
//  Created by dllo on 15/7/28.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "L_PlayListView.h"

@implementation L_PlayListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
        self.single = [L_Singleton shareManager];
        self.footTabBar = [L_footPlaytabBar shareTabBar];
    }
    return self;
}


- (void)createView
{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(SCREEN_WIDTH - 20, 30);
    
    self.collection = [[[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout] autorelease];
    self.collection.backgroundColor = [UIColor colorWithRed:180 green:180 blue:180 alpha:0.5];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    
    [self addSubview:self.collection];
    [self.collection registerClass:[D_FootCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    D_FootCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.songLable.text = [self.single.array[indexPath.item] song_name];
    cell.singLable.text = [self.single.array[indexPath.item] singer_name];
    cell.songLable.textColor = [UIColor whiteColor];
    cell.singLable.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor grayColor];
    cell.alpha = 0.8;
    return cell;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.single.array.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    PlayViewController *playVC = [[[PlayViewController alloc] init] autorelease];
    
    // 定时器开启
    [self.footTabBar.time setFireDate:[NSDate distantPast]];
    
    // 临时列表
    if (self.single.array.count == 0) {
        
    } else {
        
        NSString *url = [[[self.single.array[indexPath.item] url_list] firstObject] objectForKey:@"url"];
        [self.single playWithUrl:url];
        self.single.playUrl = url;
        self.single.state = @"playing";
        self.single.index = indexPath.item;
        
        playVC.playView.songName.text = [self.single.array[indexPath.item] song_name];
        playVC.playView.songerName.text = [self.single.array[indexPath.item] singer_name];
        [playVC.playView.showImage setImageWithURL:[NSURL URLWithString:[[[self.single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"lloo.png"]];
        [playVC.playView.play setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        
    }
    
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
